package net.oschina.archx.spring.mongo.model;

import java.io.Serializable;

/**
 * 分页模型
 *
 * @author Archx[archx@foxmail.com]
 * @date 2016/3/22 0022
 */
public class Pagination implements Serializable {

    private static final long serialVersionUID = -1420270951630610376L;

    private Long total; // 总记录

    private Integer offset; // 起始记录

    private Integer limit; // 界限

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public Integer getOffset() {
        return offset;
    }

    public void setOffset(Integer offset) {
        this.offset = offset;
    }

    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    /**
     * 是否有上一页
     *
     * @return
     */
    public boolean hasPreview() {
        return offset > 0;
    }

    /**
     * 是否有下一页
     *
     * @return
     */
    public boolean hasNext() {
        if (total == null) return false;
        return (offset + limit) < total;
    }
}
